﻿var content_html= '';
var emptyData={total:0,rows:[]};
$(function() {
    dialog_highsearch_close();
    $('#dlg-searchowner').dialog('close');
});

//初始化加载入口
$(window).load(function() {
    if (viewType == 1) {
        loadfloor();
    } else {
        loadGrid();
    }
    

    $('#cbarea').combobox('options').onSelect = function(record) {
        $('#cbbuild').combobox('options').url = "../Controller.aspx?controller=RoomBrowseController&method=GetBuildList&areacode=" + record.Code;
        $('#cbbuild').combobox('reload');
    }
    
    $('#cbarea').combobox('options').onLoadSuccess = function() {
        $('#cbarea').combobox('select', '01');
    }


    $('#mmroom').show();
    $('#mmshop').hide();
    $('#mmcar').hide();
    $('#mmclient').hide();

    fn_InitCheckBox();
});

var room_html = '<table width="100%" height="100%" style="font-size: 12px;">' +
                  '<tr>' +
                    '<td align="center"><a name="OwnerName"/></td>' +
                  '</tr>' +
                  '<tr>' +
                    '<td align="center"><a name="UseArea"/>㎡</td>' +
                  '</tr>' +
                  '<tr>' +
                    '<td align="center"><a name="OftenMobile"/></td>' +
                  '</tr></table>';
function loadfloor() {
    $('#floor').floor({
        url: '../Controller.aspx?controller=RoomBrowseController&method=GetFloorData&type=1&areacode=01&buildcode=01&usestatus=1',
        colnum: 8,
        roomspace: 5,
        roomheadfield: 'srccName',
        roomsize: { roomWidth: 110, roomHeight: 124 },
        roomcell_html: room_html,
        toolbar: '#tool',
        roomFormatStyle: function(roomTarget, roomdata) {
            if (roomdata.type == "1") {//住宅
                if (roomdata.OwnerId != '') {
                    if (roomdata.Sex == '1')
                        $('img', roomTarget).attr("src", "img/user.png"); //男
                    else
                        $('img', roomTarget).attr("src", "img/user3.png"); //女
                }
            }
            else if (roomdata.type == "2") {//门面
                $('img', roomTarget).attr("src", "img/26.png"); //
            }
            else if (roomdata.type == "3") {//停车位
                if (parseInt(roomdata.JoinFlag) == 1) {
                    $('img', roomTarget).attr("src", "img/orangebug.png");
                } else {
                    $('img', roomTarget).attr("src", "img/aquaround.png");
                }
            }
            else if (roomdata.type == "4") {//客户
                $('img', roomTarget).attr("src", "img/user2.png");
            }
        },
        onClickRoom: function(roomIndex, roomdata) {
            //        $.messager.show({
            //				title:'详细信息',
            //				msg:content_html,
            //				timeout:5000,
            //				width:200,
            //				height:300,
            //				showType:'slide'
            //			});
        },
        onDblClickRoom: function(roomIndex, roomdata) {
            btn_cashmanager_show();
        }
    });
}

function loadGrid() {
    
}

function dialog_highsearch_show() {
    $('#dialog-highsearch').dialog({modal:true});
}

function dialog_highsearch_close() {
    $('#dialog-highsearch').dialog('close');
}

function dialog_highsearch_queding(){
    var areacode=$('#cbarea').combobox('getValue');
    var buildcode=$('#cbbuild').combobox('getValue');
    var saleflag=$('#saleflag').val();
    $('#floor').floor('options').url="../Controller.aspx?controller=RoomBrowseController&method=GetFloorData&type=1&areacode="+areacode+"&buildcode="+buildcode+"&usestatus="+saleflag;
    $('#floor').floor('reload');
    dialog_highsearch_close();
    $('#highsearch').html('分类查询[住宅]');
    $('#mmroom').show();
    $('#mmshop').hide();
    $('#mmcar').hide();
    $('#mmclient').hide();
}

function floorhome_show(){  
    dialog_highsearch_show();
}

function floorshop_show(){
    $('#highsearch').html('分类查询[门面]');
    $('#floor').floor('options').url="../Controller.aspx?controller=RoomBrowseController&method=GetFloorData&type=2";
    $('#floor').floor('reload');
    $('#mmroom').hide();
    $('#mmshop').show();
    $('#mmcar').hide();
    $('#mmclient').hide();
}

function floorcar_show(){
    $('#highsearch').html('分类查询[车位]');
    $('#floor').floor('options').url="../Controller.aspx?controller=RoomBrowseController&method=GetFloorData&type=3";
    $('#floor').floor('reload');
    $('#mmroom').hide();
    $('#mmshop').hide();
    $('#mmcar').show();
    $('#mmclient').hide();
}

function floorclientele_show(){
    $('#highsearch').html('分类查询[客户]');
    $('#floor').floor('options').url="../Controller.aspx?controller=RoomBrowseController&method=GetFloorData&type=4";
    $('#floor').floor('reload');
    $('#mmroom').hide();
    $('#mmshop').hide();
    $('#mmcar').hide();
    $('#mmclient').show();
}


function fn_InitCheckBox() {
    $("#saleflag").click(function() {
        if ($("#saleflag").attr("checked")) {
            $("#saleflag").val(0);
        }
        else {
            $("#saleflag").val(1);
        }
    });
}

function btn_cashmanager_show() {//显示收银界面
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        if(parseInt(seleced.JoinFlag)==1){
            cashmanager_show();//CashManager.js中
        }else{
            $.messager.alert('提示', "选择的收银对象还没登记，无法收银操作！", 'info');
        }
    }
}

function btn_historycash_show() {//历史收银记录
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        if(parseInt(seleced.JoinFlag)==1){
            histroycash_show();//HistoryCash.js中
        }else{
            $.messager.alert('提示', "选择的收银对象还没登记，无法查看收银记录！", 'info');
        }
    }
}

function btn_roomjoin(){//房间入伙
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        if(seleced.OwnerId != ''){
            if(parseInt(seleced.JoinFlag)==0){
                $.messager.confirm('询问', '是否需要进行入伙登记？', function(r) {
                    if (r) {
                        //
                         requestAjax('../Controller.aspx?controller=RoomBrowseController&method=RoomJoin', {srccId:seleced.srccId}, function(data) {
                            $('#floor').floor('reload');
                        });
                    }
                });
            }else{
                $.messager.alert('提示', "选择的房间已入伙，无法再次入伙登记！", 'info');
            }
        }else{
            $.messager.alert('提示', "选择的房间还没维护业主信息，请先维护好此房间的业主信息后再进行入伙登记！", 'info');
        }
    }
}
function btn_cancelroomjoin(){//房间取消入伙
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        if(parseInt(seleced.JoinFlag)==1){
            $.messager.confirm('询问', '是否需要对此房间取消登记？', function(r) {
                    if (r) {
                        //
                        requestAjax('../Controller.aspx?controller=RoomBrowseController&method=CancelRoomJoin', {srccId:seleced.srccId}, function(data) {
                            $('#floor').floor('reload');
                        });
                    }
                });
            //
        }else{
            $.messager.alert('提示', "选择的房间并未入伙，无需取消登记！", 'info');
        }
    }
}

function btn_shopjoin(){//门面入伙登记
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        if(seleced.OwnerId != ''){
            if(parseInt(seleced.JoinFlag)==0){
                $.messager.confirm('询问', '是否需要进行入伙登记？', function(r) {
                    if (r) {
                        //
                        requestAjax('../Controller.aspx?controller=RoomBrowseController&method=ShopJoin', {srccId:seleced.srccId}, function(data) {
                            $('#floor').floor('reload');
                        });
                    }
                });
            }else{
                $.messager.alert('提示', "选择的门面已入伙，无法再次入伙登记！", 'info');
            }
        }else{
            $.messager.alert('提示', "选择的门面还没维护业主信息，请先维护好此门面的业主信息后再进行入伙登记！", 'info');
        }
    }
}
function btn_cancelshopjoin(){//门面取消登记
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        if(parseInt(seleced.JoinFlag)==1){
            $.messager.confirm('询问', '是否需要对此门面取消登记？', function(r) {
                    if (r) {
                        //
                        requestAjax('../Controller.aspx?controller=RoomBrowseController&method=CancelShopJoin', {srccId:seleced.srccId}, function(data) {
                            $('#floor').floor('reload');
                        });
                    }
                });
            //
        }else{
            $.messager.alert('提示', "选择的门面并未入伙，无需取消登记！", 'info');
        }
    }
}

function btn_carportjoin(){//车位销售
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        if(parseInt(seleced.JoinFlag)==0){
            //
            $('#dlgcarport_srccId').val(seleced.srccId);
            carportjoin_show();
        }else{
            $.messager.alert('提示', "选择的车位已销售，不能再次销售！", 'info');
        }
    }
}
function btn_cancelcarportjoin(){//车位停售
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        if(parseInt(seleced.JoinFlag)==1){
            $.messager.confirm('询问', '是否需要对此车位停售？', function(r) {
                    if (r) {
                        //
                        requestAjax('../Controller.aspx?controller=RoomBrowseController&method=CancelCarportJoin', {srccId:seleced.srccId}, function(data) {
                            $('#floor').floor('reload');
                        });
                    }
                });
            //
        }else{
            $.messager.alert('提示', "选择的车位并未销售，无需停售！", 'info');
        }
    }
}

function btn_customerjoin(){//客户增加
    customerjoin_show();
}
function btn_cancelcustomerjoin(){//客户删除
    var seleced = $('#floor').floor('getSelectedRoomData');
    if (seleced) {
        $.messager.confirm('询问', '是否需要删除此客户？', function(r) {
            if (r) {
                //
                requestAjax('../Controller.aspx?controller=RoomBrowseController&method=CancelCustomerJoin', {srccId:seleced.srccId}, function(data) {
                            $('#floor').floor('reload');
                        });
            }
        });
    }
}

function dlg_btnsearchowner_search(){
    var ownername=$('#dlgsearch_ownername').val();
    var tel=$('#dlgsearch_tel').val();
    var number=$('#dlgsearch_number').val();
    $('#ownerlistGrid').datagrid('options').url='../Controller.aspx?controller=RoomBrowseController&method=SearchOwner&ownername='+ownername+'&tel='+tel+'&number='+number;
    $('#ownerlistGrid').datagrid('reload');
}

function dlg_btnsearchowner_queding(){
    var seleced = $('#ownerlistGrid').datagrid('getSelected');
    if(seleced){
        if(parseInt($('#searchownerType').val())==0){
            btn_carsearchowner_queding(seleced);//CarportOperation.js
        }else{
            btn_customersearchowner_queding(seleced);//CustomerOperation.js
        }
        
        $('#dlg-searchowner').dialog('close');
    }
}